C#菜鸟提问啦~~`

来源:百度知道 编辑:UC知道 时间:2024/06/08 21:36:24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsoleApplication2
{
public class Myindex
{
private Hashtable name = new Hashtable();
public string this[int index]
{
get { return name[index].ToString(); }
set { name.Add(index, value); }
}
public int this[string aName]
{
get
{
foreach (DictionaryEntry d in name)
{
if (d.Value.ToString() == aName)
{
return Convert.ToInt32(d.Key);//这行代码是什么意思?能详细的解释一下吗?如果是类型转换的话,为什么不用d.key.int()呢?
}
}
return -1;
}
set { name.Add(value,aName); }
}

强行转换有多种,没有为什么这样而不那样一说,哪种用着方便就用哪种。
比如 int.Parse(); 括号中只能是 string 的 所以string转int可以用这个但是用Convert.toInt32();也没错

是指执行用户名令

强制转换
没听说过有int()这个方法

可以int.Parse(d.key)